package com.wxk.lambda.exercise;

import com.wxk.lambda.data.Person;

import java.util.TreeSet;

/**
 * wxk
 */
public class Exercise2 {

    public static void main(String[] args) {
        //Treeset

        //使用Lambda表达式来实现Comparator接口，并实例化一个Treeset对象
        TreeSet<Person> set = new TreeSet<>((o1, o2) -> (o2.age >= o1.age) ? -1 : 1);

        set.add(new Person("xiaoming", 10));
        set.add(new Person("lilei", 11));
        set.add(new Person("hanmeimei", 12));
        set.add(new Person("lily", 9));
        set.add(new Person("lucy", 9));
        set.add(new Person("polly", 3));
        set.add(new Person("uncle wang", 40));

        System.out.println(set);

    }
}
